package com.clps.algorithm.chapter03.不含重复字符的最长子字符串;

public class demo01 {

    public static void main(String[] args) {

    }

    public  int lengthOfLonGestSubtring(String s){
        int[] counts = new int[256];
        int longest = s.length()>0 ?1:0;
        for (int i = 0, j = -1; i < s.length(); ++i) {
            counts[s.charAt(i)]++;
            while (hasGreaterThan(counts)){
                ++j;
                counts[s.charAt(j)]--;
            }

            longest = Math.max(i-j,longest);
        }
        return  longest;
    }

    private boolean hasGreaterThan(int[] counts) {
        for (int count : counts) {
            if(count>1){
                return  true;
            }
        }
        return false;
    }
}

